function changeGridButtonState(isDisabled){
$(".GridButton").each( function() {					 
	var src = $(this).attr("src");
	var replaceSource = isDisabled ? ".png" : "_disabled" ;
	var replaceWith = isDisabled ? "_disabled.png" : "" ;
	src = src.replace(replaceSource,replaceWith);
	$(this).attr("src", src);

	if (isDisabled)
		$(this).attr("disabled", "disabled");	
	else
		$(this).removeAttr("disabled");

});
}

/*
 * get_grid_doc_ready_javascript:	
 *	This function returns javascript loaded in the doc ready function of JQuery.	It preps the page to handle the 
 *	the buttons add, copy, view, delete 
 *	
 *	$use_copy : means that the copy button will be used
*/
function getGridDocReady() {

	$("#_gridAddTop").click(function() 
	{
		var linkUrl = '/index.php?/member_car/add_car';
		window.location.href = linkUrl;
		return true;
	});

	$("#_gridViewTop").click(function() 
	{
        var isRegularRowSelect = $('.gridRowSelected a').length > 0;
		var linkUrl = $('.grid' + (isRegularRowSelect ? '' : 'Alternating' ) + 'RowSelected a').attr('href');
		window.location.href = linkUrl;
		return true;
	});

	$("#_gridDeleteTop").click(function() 
	{
		var confirmDelete	=	confirm('You are about to delete the car selected and all its photographs.\n\n\Click ok to confirm this action.');
		if (confirmDelete   !=  true)
		  return false;

        var isRegularRowSelect = $('.gridRowSelected a').length > 0;
		var linkUrl = $('.grid' + (isRegularRowSelect ? '' : 'Alternating' ) + 'RowSelected a').attr('href').replace('edit','delete');        
        linkUrl     = linkUrl.replace('member_car','member_profile');

		window.location.href = linkUrl
		return true;
	});
	

	$(".GridRadio").click(function() {
			
            //Clear any selected rows
            $(".GridRadio").each(function(){
                var rowClassName = $(this).parent().parent().attr("class");
                $(this).parent().parent().attr("class",rowClassName.replace("Selected",""));
            });
            
            //Hightlight the row selected
			var rowVar = $(this).parent().parent();
			var className = rowVar.attr("class");
			rowVar.attr("class",className + "Selected");
			
			changeGridButtonState(false);
			return true;
		});

}
